<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let input=`3
        1 0 223
        2 0 323
        3 2 1203`
        let list=input.split('\n').map(v=>v.trim())
        let N=parseInt(list.shift())
        list=list.map(v=>v.split(' ').map(j=>parseInt(j)))

        let obj={}
        let visited=new Set()
        let money=new Array(N+1).fill(0)

        for(let i=0;i<N;i++){
            money[list[i][0]]=list[i][2] 

            if(visited.has(list[i][1])){
                obj[list[i][1]].push(list[i][0])
                
            }else{                
                visited.add(list[i][1])
                obj[list[i][1]]=[list[i][0]]
            }
        }      
        let boosindex=money.indexOf(0) 
        
        let T=[boosindex]
        function dps(){
            if(T.length){

            }

        }


        console.log(N,list,obj,visited);
        
        
        
        


        


    </script>
</body>
</html>